﻿using System;
using FamilyBook.UI.WPF.ViewModels;

namespace FamilyBook.UI.WPF.Interaction
{
    public class DetailsInteractionRequest<TViewModel> where TViewModel : IViewModel
    {
        public event EventHandler<DetailsInteractionRequestEventArgs> Raised;

        public void Raise(TViewModel viewModel, Action<TViewModel> callbackCompleted, Action<TViewModel> callbackCanceled)
        {
            Action<TViewModel> callback = x =>
                                  {
                                      if (x.Result == ViewModelResult.Confirm)
                                          callbackCompleted(x);
                                      else
                                          callbackCanceled(x);
                                  };
            this.Raised(this, new DetailsInteractionRequestEventArgs(viewModel, () => callback(viewModel)));
        }
    }
}
